package com.project.controller;

import com.project.dao.ClassDao;
import com.project.dao.UserDao;
import com.project.entity.ClassEntity;
import com.project.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lyl
 * description:
 */
@RestController
@RequestMapping
public class UserController {
    @Autowired
    UserDao userDao;
    @Autowired
    ClassDao classDao;

    @GetMapping("addUserAndClass")
    private String addUser() {
        ClassEntity classEntity = new ClassEntity();
        classEntity.setClassname("t-15");
        classDao.save(classEntity);
        for (int i = 0; i < 50; i++) {
            UserEntity u = new UserEntity();
            u.setPassword("10" + i);
            u.setUsername("张三" + i);
            u.setClassEntity(classEntity);
            userDao.save(u);
        }
        return "保存成功";
    }

    @GetMapping("findAll")
    private List<UserEntity> findAll() {
        return (List<UserEntity>) userDao.findAll();
    }

    @GetMapping("findOne/{userId}")
    private UserEntity findOne(@PathVariable long userId) {
        return userDao.findUserEntitiesByUserId(userId);
    }


}
